package top.drinyeit.nongmao.common;

import android.content.Context;
import android.support.annotation.ArrayRes;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;

/**
 * Created by YJY on 2017/9/21.
 * 通用ViewPager适配器
 */

public class CommonPagerAdapter extends FragmentPagerAdapter {

    private List<Fragment> fragments;
    private Context context;
    private int arrayId;

    public CommonPagerAdapter(Context context, List<Fragment> fragments, @ArrayRes int arrayId, FragmentManager fragmentManager) {
        super(fragmentManager);
        this.context = context;
        this.fragments = fragments;
        this.arrayId = arrayId;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return context.getResources().getStringArray(arrayId)[position];
    }
}
